package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 用于创建测试用的交换机和队列，只用执行一次
 */
public class BiInitMain {
    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("1.95.168.78");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("ZYHzyh147@");
        factory.setVirtualHost("/myapp");
        try {
            Connection connection = factory.newConnection();
            Channel channel1 = connection.createChannel();
            String EXCHANGE_NAME=BiMqConstant.BI_EXCHANGE_NAME;
            channel1.exchangeDeclare(EXCHANGE_NAME, "fanout");
            String queueName = BiMqConstant.BI_QUEUE_NAME;
            channel1.queueDeclare(queueName, true, false, false, null);
            channel1.queueBind(queueName, EXCHANGE_NAME, BiMqConstant.BI_ROUTING_KEY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
